package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiAd;
import com.lk.ii.service.IIiAdService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 广告位管理Controller
 * 
 * @author lk
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ii/ad")
public class IiAdController extends BaseController
{
    private String prefix = "ii/ad";

    @Autowired
    private IIiAdService iiAdService;

    @RequiresPermissions("ii:ad:view")
    @GetMapping()
    public String ad()
    {
        return prefix + "/ad";
    }

    /**
     * 查询广告位管理列表
     */
    @RequiresPermissions("ii:ad:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiAd iiAd)
    {
        startPage();
        List<IiAd> list = iiAdService.selectIiAdList(iiAd);
        return getDataTable(list);
    }

    /**
     * 导出广告位管理列表
     */
    @RequiresPermissions("ii:ad:export")
    @Log(title = "广告位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiAd iiAd)
    {
        List<IiAd> list = iiAdService.selectIiAdList(iiAd);
        ExcelUtil<IiAd> util = new ExcelUtil<IiAd>(IiAd.class);
        return util.exportExcel(list, "ad");
    }

    /**
     * 新增广告位管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告位管理
     */
    @RequiresPermissions("ii:ad:add")
    @Log(title = "广告位管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiAd iiAd)
    {
        iiAd.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiAdService.insertIiAd(iiAd));
    }

    /**
     * 修改广告位管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiAd iiAd = iiAdService.selectIiAdById(id);
        mmap.put("iiAd", iiAd);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告位管理
     */
    @RequiresPermissions("ii:ad:edit")
    @Log(title = "广告位管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiAd iiAd)
    {
        iiAd.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiAdService.updateIiAd(iiAd));
    }

    /**
     * 删除广告位管理
     */
    @RequiresPermissions("ii:ad:remove")
    @Log(title = "广告位管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiAdService.deleteIiAdByIds(ids));
    }
}
